<template>
  <div class="search-result">
    <!-- Vantlist 组件都需要做滚动加载 -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.art_id" :title="item.title" />
    </van-list>
  </div>
</template>

<script>
import { getSearchResults } from "@/api/search";
export default {
  name: "SearchResult",
  components: {},
  props: {
    searchText: String,
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
    };
  },

  methods: {
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
    },
      async onLoad() {
      try {
        let { data } = await getSearchResults({
          page: this.page,
          per_page: 10,
          q: this.searchText,
        });
        console.log(data);
        this.list.push(...data.data.results);
        this.loading = false;
        if (data.data.results.length < 10) {
          this.finished = true;
        } else {
          this.page++;
        }
      } catch (error) {
        console.log(error);
      }
    },
   
  },
};
</script>

<style scoped lang="less"></style>